Skip to content

Conversation

@tormodvolden
Copy link
Contributor

@tormodvolden tormodvolden commented Nov 15, 2024

Adds the --ble option which specifies the Bluetooth device address.

Seems to work somewhat, transfers to the device, but the expected flashing doesn't happen after reset.
EDIT: Works fine when I specify the correct slot.

@tormodvolden
Copy link
Contributor Author

Your linter is not happy, but it doesn't say anything about what is wrong...

@JPHutchins
Copy link
Collaborator

Your linter is not happy, but it doesn't say anything about what is wrong...

Appears that it needs black formatting. You can run lint locally to check it out.

@JPHutchins
Copy link
Collaborator

Wow, I didn't realize this could be so simple! Re: FW upgrades, if "image upload" is used, then the FW would not be expected to swap. To run a routine that swaps the FW, try "upgrade".

@tormodvolden
Copy link
Contributor Author

lint locally wasn't any more helpful. Is there a verbose of fix option?

My test was with "upgrade".

@JPHutchins
Copy link
Collaborator

lint locally wasn't any more helpful. Is there a verbose of fix option?

My test was with "upgrade".

You'll need to run black on the files that need to be formatted.

May be helpful to enable debug logging, though some error should be indicated if the swap request is rejected.

You can run image state-read to see if your upgrade is correctly in the secondary.

@tormodvolden
Copy link
Contributor Author

I tried image state-read. Is this probably the old firmware?

ImageState(
    slot=0,
    version='0.0.0',
    image=None,
    hash=HashBytes(
        '<hash>'
    ),
    bootable=True,
    pending=False,
    confirmed=True,
    active=True,
    permanent=False
)
splitStatus: 0

@JPHutchins
Copy link
Collaborator

I should add --diff --color to the envr alias: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#diff

@JPHutchins
Copy link
Collaborator

I tried image state-read. Is this probably the old firmware?


ImageState(

    slot=0,

    version='0.0.0',

    image=None,

    hash=HashBytes(

        '<hash>'

    ),

    bootable=True,

    pending=False,

    confirmed=True,

    active=True,

    permanent=False

)

splitStatus: 0



Likely! You can try image upload --slot 2, then read again and see what you see.

@tormodvolden
Copy link
Contributor Author

Slot 2 not 1?

@tormodvolden
Copy link
Contributor Author

Yes, black --diff is great and worth mentioning.

@tormodvolden
Copy link
Contributor Author

I took the chance on slot 2 :)

ImageState(
    slot=0,
    version='0.0.0',
    image=None,
    hash=HashBytes(
        '<same hash>'
    ),
    bootable=True,
    pending=False,
    confirmed=True,
    active=True,
    permanent=False
)
ImageState(
    slot=1,
    version='0.0.0',
    image=None,
    hash=HashBytes(
        '<another hash>'
    ),
    bootable=True,
    pending=False,
    confirmed=False,
    active=False,
    permanent=False
)
splitStatus: 0

@tormodvolden
Copy link
Contributor Author

There are lots of (every packet) these warnings when uploading:

           WARNING  Overriding self.version=<Version.V2: 1> with message.py:115
                    self.header.version=<Version.V1: 0> from the               
                    provided header. - message:115                             

References intercreate#12

Signed-off-by: Tormod Volden <[email protected]>
@tormodvolden
Copy link
Contributor Author

tormodvolden commented Nov 15, 2024

Are you happy with the command syntax? smpmgr --ble <address> ?
Or did you have something else in mind, like smpmgr --ble --port <address> ?

@tormodvolden
Copy link
Contributor Author

The upgrade gave no other warnings.

⠋ Waiting for response to ResetWrite... OK
Upgrade complete.

@tormodvolden
Copy link
Contributor Author

I used upgrade --slot 2 and it worked! I am a happy camper! Seems like this is the only SMP over BLE command tool on Linux. I tried also AuTerm but it is a GUI with no possibilities of scripting.

@JPHutchins
Copy link
Collaborator

JPHutchins commented Nov 15, 2024

Slot 2 not 1?

Yes, this is a whole mess! You can read about it here, it needs to be improved: #3

There are lots of (every packet) these warnings when uploading:

           WARNING  Overriding self.version=<Version.V2: 1> with message.py:115
                    self.header.version=<Version.V1: 0> from the               
                    provided header. - message:115                             

There are 2 parts to this:

Are you happy with the command syntax? smpmgr --ble <address> ?
Or did you have something else in mind, like smpmgr --ble --port <address> ?

For now, smpmgr --ble [address] is great... though we need to make address optional - it will find the device as long as the SMP service is advertised. This will be feature version 0.9.0.

This will all be different in smpmgr 1.0.0. It's become clear that each transport should be its own subcommand group so that it can handle all the different arguments. The transport groups will be usb uart ble can udp. Usage like smp uart [a bunch of transport specific options] upgrade [args].

I used upgrade --slot 2 and it worked! I am a happy camper! Seems like this is the only SMP over BLE command tool on Linux. I tried also AuTerm but it is a GUI with no possibilities of scripting.

Great! For scripting, I might recommend using smpclient directly - there are lots of examples scripts in that repo as HW integration tests. You can see example implementation in ESPHome here, for example: https://github.com/esphome/esphome/pull/6075/files#diff-493f483da80bddf50eae6653dda1843815a142b1b1912e4df0541aa3b7097439

For Linux shell scripting, maybe smpmgr is better. I'd recommend pipx over the portable though.

Thanks for the contribution, I will test and merge ASAP.

FYI: I've tested running parallel upgrades, even on multiple different transports, and this will definitely be a feature. E.g. it can be configured to scan for all BLE devices and upgrade them all in parallel, or upgrade all attached USB devices - good potential for factory tooling! No impact to speed of upgrade.

BTW, what is your upload speed? We're expecting 10kB/s -> 25kB/s over BLE. I usually see about 15kB/s in Windows.

@tormodvolden
Copy link
Contributor Author

Just noted that when I use --slot so it works, this is printed at the end:
The device may take a few minutes to complete FW swap.

The speed I get is 40.9 kB/s according to the progress bar when it is done.

@JPHutchins
Copy link
Collaborator

The speed I get is 40.9 kB/s according to the progress bar when it is done.

That's wild. One thing that can cause it to report really fast uploads is if the image you're uploading is already on the device. When that happens, it sees that the SHA matches and doesn't do the upload.

What chip are you testing?

@tormodvolden
Copy link
Contributor Author

It is an nRF5340 and my laptop has a Intel Corp. AX201 Bluetooth module. I can test again with a clock and new image.

@tormodvolden
Copy link
Contributor Author

For Linux shell scripting, maybe smpmgr is better. I'd recommend pipx over the portable though.

Would be nice to have a release in pipx with BLE support soon :)

@JPHutchins
Copy link
Collaborator

For Linux shell scripting, maybe smpmgr is better. I'd recommend pipx over the portable though.

Would be nice to have a release in pipx with BLE support soon :)

Probably within a few days! I want to test it with HW.

@tormodvolden
Copy link
Contributor Author

The firmware is 326700 bytes and the whole command (measured with "time") is e.g. 10.3 s so with the connection overhead removed I guess the transport is somewhere around 9 seconds. That would give 36 KB/s, or 32 KB/s included the whole invocation and connection overhead. But the reported speed from smpmgr is above 40 KB/s, also seen 44.4 KB/s once.

@JPHutchins
Copy link
Collaborator

The firmware is 326700 bytes and the whole command (measured with "time") is e.g. 10.3 s so with the connection overhead removed I guess the transport is somewhere around 9 seconds. That would give 36 KB/s, or 32 KB/s included the whole invocation and connection overhead. But the reported speed from smpmgr is above 40 KB/s, also seen 44.4 KB/s once.

OK, that seems to confirm the speeds. Hard for there to be a math error in the KB/s calculation.

I gotta get a 53 dev kit. That BLE transfer is almost as fast as USB speeds on other boards, which makes me wonder how fast the USB transport upload is on that chip.

The 52840 is the one where I tend to see 10-25 KB/s via BLE.

@JPHutchins
Copy link
Collaborator

OK, it's working for me on Windows + nrf 52840. I am connecting by using device name, e.g. smpmgr --ble MyDeviceName os echo hello.

I am going to push some other changes to main since I ended up needing longer timeouts (Windows BLE is ... not fun).

Will tag you on release.

@JPHutchins JPHutchins merged commit efcd19e into intercreate:main Nov 16, 2024
@JPHutchins JPHutchins mentioned this pull request Nov 16, 2024
@JPHutchins
Copy link
Collaborator

@tormodvolden OK, should be on pipx now, LMK if there are any problems: https://pypi.org/project/smpmgr/

@tormodvolden
Copy link
Contributor Author

@tormodvolden OK, should be on pipx now, LMK if there are any problems: https://pypi.org/project/smpmgr/

Wow! Thanks so much!

@tormodvolden tormodvolden deleted the ble_support branch November 16, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants